﻿using System;
using System.Collections.Generic;
using JTLeigh.Commerce.Spencer.Features.ProductFeedback.Business.Behaviors.ProductFeedbackSelection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ProductFeedbackE = JTLeigh.Commerce.Spencer.Features.ProductFeedback.Common.Entities.ProductFeedback;

namespace JTLeigh.Commerce.Spencer.Features.ProductFeedback.Business.UnitTests.Behaviors.ProductFeedbackSelection
{

    /// <summary>
    /// Unit tests for the <see cref="DateAscendingBehavior"/> class.
    /// </summary>
    [TestClass]
    public class DateAscendingBehaviorFixture
    {

        #region Methods

        #region SelectProductFeedback

        /// <summary>
        /// Ensures the <see cref="DateAscendingBehavior.SelectProductFeedback"/> method returns 
        /// the original feedback list, ordered by date (descending).
        /// </summary>
        [TestMethod]
        public void TestSelectProductFeedback()
        {
            List<ProductFeedbackE> originalFeedbackList;
            Dictionary<Guid, ProductFeedbackE> originalFeedbackDictionary;
            DateAscendingBehavior behavior;
            IList<ProductFeedbackE> selectedFeedbackList;

            originalFeedbackList = new List<ProductFeedbackE>();
            originalFeedbackList.Add(new ProductFeedbackE { FeedbackId = Guid.NewGuid(), DateAdded = new DateTime(2009, 01, 01) });
            originalFeedbackList.Add(new ProductFeedbackE { FeedbackId = Guid.NewGuid(), DateAdded = new DateTime(2009, 02, 01) });
            originalFeedbackList.Add(new ProductFeedbackE { FeedbackId = Guid.NewGuid(), DateAdded = new DateTime(2009, 02, 02) });
            originalFeedbackList.Add(new ProductFeedbackE { FeedbackId = Guid.NewGuid(), DateAdded = new DateTime(2008, 01, 01) });
            originalFeedbackList.Add(new ProductFeedbackE { FeedbackId = Guid.NewGuid(), DateAdded = new DateTime(2008, 02, 01) });
            originalFeedbackList.Add(new ProductFeedbackE { FeedbackId = Guid.NewGuid(), DateAdded = new DateTime(2008, 02, 02) });

            originalFeedbackDictionary = new Dictionary<Guid, ProductFeedbackE>();
            foreach (ProductFeedbackE originalFeedback in originalFeedbackList)
            {
                originalFeedbackDictionary.Add(originalFeedback.FeedbackId, originalFeedback);
            }

            behavior = new DateAscendingBehavior();

            selectedFeedbackList = behavior.SelectProductFeedback(originalFeedbackDictionary);

            Assert.AreSame(originalFeedbackList[3], selectedFeedbackList[0]); // 2008/01/01
            Assert.AreSame(originalFeedbackList[4], selectedFeedbackList[1]); // 2008/02/01
            Assert.AreSame(originalFeedbackList[5], selectedFeedbackList[2]); // 2008/02/02
            Assert.AreSame(originalFeedbackList[0], selectedFeedbackList[3]); // 2009/01/01
            Assert.AreSame(originalFeedbackList[1], selectedFeedbackList[4]); // 2009/02/01
            Assert.AreSame(originalFeedbackList[2], selectedFeedbackList[5]); // 2009/02/02
        }

        #endregion // SelectProductFeedback

        #endregion // Methods

    }

}
